public class Rotate2 {
    // leetcode 旋转图像
    // https://leetcode.cn/problems/rotate-image/description/?envType=study-plan-v2&envId=top-100-liked
    public void rotate(int[][] matrix) {
        int len = matrix.length;
        int top = 0, bottom = len-1, left = 0, right = len-1;
        for (int i = 0; i < len/2; i++) {
            int index = 0;
            while (left + index < right) {
                int tmp = matrix[top][left+index];
                matrix[top][left+index] = matrix[bottom-index][left];
                matrix[bottom-index][left] = matrix[bottom][right-index];
                matrix[bottom][right-index] = matrix[top+index][right];
                matrix[top+index][right] = tmp;
                index++;
            }
            top++;
            bottom--;
            left++;
            right--;
        }
    }
}
